package com.cyandpos.pad.cateringformat.choosemenu.presenter;

import com.cyandpos.pad.cateringformat.choosemenu.model.QueryFoodModel;
import com.cyandpos.pad.cateringformat.choosemenu.model.QueryFoodModelImpl;
import com.cyandpos.pad.cateringformat.choosemenu.view.QueryFoodView;
import com.cyandpos.pad.posdata.CyFood;
import com.cyandpos.pad.posdata.DjdData;
import com.cyandpos.pad.posdata.Goods;
import com.cyandpos.pad.posdata.Member;
import com.cyandpos.pad.posdata.Order;
import com.cyandpos.pad.posdata.QueryGoodParam;
import com.cyandpos.pad.posdata.QueryMemberReq;
import com.cyandpos.pad.posdata.QueryOrderReq;
import com.cyandpos.pad.posdata.TicketInfo;

import java.util.List;

public class QueryFoodPresenterImpl implements QueryFoodPresenter, QueryFoodModelImpl.OnLoadQueryFoodListener {
    private QueryFoodModel queryFoodModel;
    private QueryFoodView queryFoodView;

    public QueryFoodPresenterImpl(QueryFoodView queryFoodView){
        this.queryFoodView=queryFoodView;
        queryFoodModel=new QueryFoodModelImpl();
    }
    @Override
    public void loadQueryFood(String shopid) {
        queryFoodView.showProgress("正在加载....");
        queryFoodModel.loadQueryFood(shopid,this);
    }

    @Override
    public void createSaleId(String orderNo,String tableNo,String personNo) {
        queryFoodView.showProgress("创建订单号...");
        queryFoodModel.createOrderNo(orderNo,tableNo,personNo, new QueryFoodModel.onCreateOrderNoListener() {
            @Override
            public void onCreateOrderNoSuccess(String orderNo) {
                queryFoodView.dismissProgress();
                queryFoodView.createOrderNO(orderNo);
            }

            @Override
            public void onCreateOrderNoFailure(String errorMsg) {
                queryFoodView.dismissProgress();
                queryFoodView.QueryFoodFailure(errorMsg);
            }
        });
    }

    @Override
    public void queryGoods(QueryGoodParam goodsCode, TicketInfo ticketInfo, int subInx) {
        queryFoodView.showProgress("查询商品...");
        queryFoodModel.queryGoods(goodsCode, ticketInfo, subInx, new QueryFoodModel.OnQueryGoodsInfoListener() {
            @Override
            public void onQueryGoodsInfoSuccess(Goods goods) {
                queryFoodView.dismissProgress();
                queryFoodView.handleGoods(goods);
            }

            @Override
            public void onQueryGoodsInfoFailure(String errorMsg) {
                queryFoodView.dismissProgress();
                queryFoodView.QueryFoodFailure(errorMsg);
            }
        });
    }

    @Override
    public void frontDiscount(String disType, String money, Goods goods, String orderNo, boolean isSingle) {
        queryFoodView.showProgress("查询折扣...");
        queryFoodModel.frontDiscount(disType, money, goods, orderNo, isSingle, new QueryFoodModel.OnFrontDiscountListener() {
            @Override
            public void onFrontDiscountSuccess(List<Goods> goods, boolean isSingle) {
                queryFoodView.dismissProgress();
                queryFoodView.frontDiscount(goods,isSingle);
            }

            @Override
            public void onFrontDiscountFailure(String errorMsg) {
                queryFoodView.dismissProgress();
                queryFoodView.QueryFoodFailure(errorMsg);
            }
        });
    }

    @Override
    public void queryMember(QueryMemberReq requestParam) {
        queryFoodView.showProgress("查询会员...");
        queryFoodModel.queryMember(requestParam, new QueryFoodModel.OnQueryMemberListener() {
            @Override
            public void OnQueryMemberSuccess(Member member) {
                queryFoodView.dismissProgress();
                queryFoodView.addMember(member);
            }

            @Override
            public void OnQueryMemberFailure(String errorMsg) {
                queryFoodView.dismissProgress();
                queryFoodView.QueryFoodFailure(errorMsg);
            }
        });
    }

    @Override
    public void cancelOrder(String orderNo) {
        queryFoodView.showProgress("取消订单...");
        queryFoodModel.cancelOrder(orderNo, new QueryFoodModel.onCancelOrderListener() {
            @Override
            public void onCancelOrderSuccess(String orderNo) {
                queryFoodView.dismissProgress();
                queryFoodView.cancelOrder(orderNo);
            }

            @Override
            public void onCancelOrderFailure(String errorMsg) {
                queryFoodView.dismissProgress();
                queryFoodView.QueryFoodFailure(errorMsg);
            }
        });
    }

    @Override
    public void preparePay(TicketInfo ticketInfo,boolean isPromotion) {
        queryFoodView.showProgress("准备付款...");
        queryFoodModel.onPreparePay(ticketInfo, isPromotion,new QueryFoodModel.onPreparePayListener() {
            @Override
            public void onPreparePaySuccess(TicketInfo ticketInfo,boolean isPromotion) {
                queryFoodView.dismissProgress();
                queryFoodView.preparePay(ticketInfo,isPromotion);
            }

            @Override
            public void onPreparePayFailure(String errorMsg) {
                queryFoodView.dismissProgress();
                queryFoodView.QueryFoodFailure(errorMsg);
            }
        });
    }

    @Override
    public void queryOrderInfoEexcute(QueryOrderReq req) {
        queryFoodView.showProgress("查询订单...");
        queryFoodModel.QueryOrderInfoEexcute(req, new QueryFoodModel.onQueryOrderListener() {
            @Override
            public void onQueryOrderSuccess(List<Order> orderList, double orderCount) {
                queryFoodView.dismissProgress();
                queryFoodView.queryOrder(orderList,orderCount);
            }

            @Override
            public void onQueryOrderFailure(String errorMsg) {
                queryFoodView.dismissProgress();
                queryFoodView.QueryFoodFailure(errorMsg);
            }
        });
    }

    @Override
    public void onLoadQueryFoodSuccess(List<CyFood> FoodList) {
        queryFoodView.dismissProgress();
        queryFoodView.QueryFoodSuccess(FoodList);
    }

    @Override
    public void onLoadQueryFoodFailure(String errorMsg) {
        queryFoodView.dismissProgress();
        queryFoodView.QueryFoodFailure(errorMsg);
    }
}
